select spu.*,
IFNULL(log.totalMoney,0) totalMoney,
IFNULL(mmc.collectCount,0) collectCount,
IFNULL(sku.sku_sales,0) skuSales
from jd_goods_spu spu
left join (select sum(pay_money) totalMoney,goods_id from jd_order_money_log  group by goods_id) log on log.goods_id = spu.id
left join (select count(*) collectCount,goods_id from jd_member_collect group by goods_id) mmc on mmc.goods_id = spu.id
left join (select sum(sku_sales) sku_sales,goods_id from jd_goods_sku group by goods_id) sku on sku.goods_id = spu.id
<#if flag?? && flag == '1'>
    order by totalMoney desc
</#if>
<#if flag?? && flag == '2'>
    order by skuSales desc
</#if>
LIMIT  ${page} , ${rows}
